package com.duck.duckchatbackend.controller;
import com.duck.duckchatbackend.annotation.GlobalInterceptor;
import com.duck.duckchatbackend.entity.po.UserInfo;
import com.duck.duckchatbackend.entity.query.UserInfoQuery;
import com.duck.duckchatbackend.entity.vo.PaginationResultVO;
import com.duck.duckchatbackend.entity.vo.ResponseVO;
import com.duck.duckchatbackend.service.UserInfoService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

@RestController("adminUserInfoController")
@RequestMapping("/admin")
public class AdminUserInfoController extends  ABaseController{
     @Resource
     private UserInfoService userInfoService;
     @RequestMapping("/loadUser")
     @GlobalInterceptor(checkAdmin = true)
     public ResponseVO loadUser(UserInfoQuery userInfoQuery){
         userInfoQuery.setOrderBy("create_time desc");
         PaginationResultVO<UserInfo> result = userInfoService.findListByPage(userInfoQuery);
         return this.getSuccessResponseVO(result);
     }

     @RequestMapping("/updateUserStatus")
     @GlobalInterceptor(checkAdmin = true)
     public ResponseVO updateUserStatus(@NotNull Integer status, @NotEmpty String userId){
         userInfoService.updateUserStatus(status,userId);
         return  getSuccessResponseVO(null);
     }

     @RequestMapping("/forceOffLine")
     @GlobalInterceptor(checkAdmin = true)
     public ResponseVO forceOffLine(@NotEmpty String userId){
         userInfoService.forceOffLine(userId);
         return  getSuccessResponseVO(null);
     }
}
